package com.whub507.msgmanager.sso.context;

/**
 * 当前用户线程上下文
 * 
 * @author wcl
 *
 */
public abstract class ThreadLocalUtil {

	private static ThreadLocal<ContextUser> threadContextUserLocal = new ThreadLocal<ContextUser>();

	public static void setContextUser(ContextUser contextUser) {
		threadContextUserLocal.set(contextUser);
	}

	public static ContextUser getContextUser() {
		return threadContextUserLocal.get();
	}

	public static void clearContextUser() {
		threadContextUserLocal.remove();
	}

	public static String getUserDomainId() {
		if (null == threadContextUserLocal.get()) {
			throw new RuntimeException("ThreadLocalUtil.ContextUserIsNull");
		}
		return threadContextUserLocal.get().getDomainId();
	}

	public static String getUserId() {
		if (null == threadContextUserLocal.get()) {
			throw new RuntimeException("ThreadLocalUtil.ContextUserIsNull");
		}
		return threadContextUserLocal.get().getUserID();
	}
}
